package com.li.system.controller.sysuser;

import com.li.common.core.constants.HttpConstants;
import com.li.common.core.controller.BaseController;
import com.li.common.core.domain.R;
import com.li.common.core.domain.vo.LoginUserVO;
import com.li.system.domain.sysuser.dto.LoginDTO;
import com.li.system.domain.sysuser.dto.SysUserSaveDTO;
import com.li.system.domain.sysuser.vo.SysUserVO;
import com.li.system.service.sysuser.impl.SysUserServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



@RestController
@RequestMapping("/sysuser")
@Tag(name = "管理员接口")
public class SysUserController extends BaseController {

    @Autowired
    private SysUserServiceImpl sysUserService;
    @PostMapping("/login")
    @Operation(summary = "管理员登录", description = "根据账号密码进行管理员登录")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3102", description = "用户不存在")
    @ApiResponse(responseCode = "3103", description = "用户名或密码错误")
    public R<String> login(@RequestBody LoginDTO loginDTO){
        return sysUserService.login(loginDTO.getUserAccount(), loginDTO.getPassword());
    }

    @DeleteMapping("/logout")
    public R<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
         return toR(sysUserService.logout(token));
    }

    @GetMapping("/info")
    public R<LoginUserVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return sysUserService.info(token);
    }


    @PostMapping("/add")
    @Operation(summary = "添加管理员", description = "根据提供信息添加管理员")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3101", description = "用户已存在")
    public R<Void> add(@RequestBody SysUserSaveDTO sysUserSaveDTO){
        return toR(sysUserService.add(sysUserSaveDTO));
    }

    @DeleteMapping("/{userId}")
    @Operation(summary = "删除管理员", description = "根据id删除管理员")
    @Parameters(value =  {
            @Parameter(name = "userId", in = ParameterIn.PATH, description = "管理员Id")
    })
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3102", description = "用户不存在")
    public R<Void> delete(@RequestBody SysUserSaveDTO sysUserSaveDTO){
        return null;
    }

    @GetMapping("/detail")
    @Operation(summary = "管理员详情", description = "根据id获取管理员详情")
    @Parameters(value =  {
            @Parameter(name = "userId", in = ParameterIn.QUERY, description = "管理员Id"),
            @Parameter(name = "sex", in = ParameterIn.QUERY, description = "性别")
    })
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3102", description = "用户不存在")
    public R<SysUserVO> detail(@RequestParam(required = true) Long userId, @RequestParam(required = false) String sex) {
        return null;
    }
}
